package se.wangs.visitor;

import org.junit.Test;
import se.wangs.visitor.impl.Candy;
import se.wangs.visitor.impl.DiscountVisitor;
import se.wangs.visitor.impl.Fruit;
import se.wangs.visitor.impl.Wine;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;

/**
 * * -- coding: UTF-8 -- *
 *
 * @author wangs
 * @date 2023/12/18 9:53
 * @description 客户访问类
 */
public class ClientTest {

    @Test
    public void client01() {
        // 1.构造商品
        Candy candy = new Candy("小黑兔奶糖", LocalDate.of(2018, 10, 1), 20.00f);
        // 2.构造访问类
        Visitor discountVisitor = new DiscountVisitor(LocalDate.of(2019, 1, 1));
        // 3.直接访问
        discountVisitor.visit(candy);
    }

    @Test
    public void client02() {
        List<Product> products = Arrays.asList(
                new Candy("小黑兔奶糖", LocalDate.of(2018, 10, 1), 20.00f),
                new Wine("猫泰白酒", LocalDate.of(2017, 1, 1), 1000.00f),
                new Fruit("草莓", LocalDate.of(2018, 12, 26), 10.00f, 2.5f));
        Visitor discountVisitor = new DiscountVisitor(LocalDate.of(2018, 1, 1));//迭代购物车轮流结算
        for (Product product : products) {
            // discountVisitor.visit(product); // 此处报错
            product.accept(discountVisitor);
        }
    }
}
